registerJQueryFunction(function(selector){
        /**
         * Triggers loading an EJS template to the targeted element.
         */
        selector('[load_ejs]').click(function(){
                var ejsName=$(this).attr('load_ejs');
                ejsData=$(this).data('pass_to_ejs');
                $(this).targetedElement().htmlJQ(renderEjs(ejsName,ejsData));
        });

        selector('[close_parent_on_click]').click(function(){
                $(this).closest($(this).attr('close_parent_on_click')).remove();
        });
});

/**
 * The initial function that loads the initial screen.
 */
function loadHomeScreen(data){
    ajaxRequest('navigation','home',data||{},function(result){
            $('#mainContainer').htmlJQ(renderEjs(result.ejs,result));
            if(result.callFunctions){
                var runFunctions=function(){
                    for(var functionName in result.callFunctions){
                        getFunction(functionName).apply(Window,[].concat(result.callFunctions[functionName]));
                    }
                };
                if(window.FB){
                    runFunctions();
                }else{
                    window.runAfterFacebookInit=runFunctions;
                }
            }
            if($.isEmptyObject(result.callFunctions)){
                $('#mainContainer input[name=search_string]').focus();
            }
    });
}

/**
 * Moves the main search form to the top of the screen.
 */
function animateToMainSearchLayout(){
    $('#main_search_form').animate({
            'top':0
        },{
            duration:900,
            easing:'easeInOutBack'
    });
    var logo=$('#ilenderImg');
    //Make the logo's centered by it's left css instead of align="center":
    var logoImage=logo.find('img');
    logo.css('left',logoImage.position().left);
    logo.width(logoImage.width());
    logo.attr('align',null);
    logoImage.css('cursor','pointer');
    logo.animate({
            'top':20,
            'left':0
        },{
            duration:1300,
            specialEasing:{
                top:'easeOutElastic',
                left:'easeOutQuart'
            }
    });
    $('#post_request_or_item').animate({
            'left':0,
            //'top':40+logoImage.height(),
        },{
            duration:1100,
            easing:'easeOutQuart'
    });
    fixLayout();
}

/**
 * Load the "Ask For" button to it's containing element.
 */
function buttonForNotFoundRequest(){
    $('#post_request_or_item').htmlJQ(renderEjs('requests/open_new_request_button'));
}
